package com.example.backend.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description TODO
 * @Author CDHong
 * @Date Created in 2024/10/23 10:21
 * @Version 1.0
 */
@Data
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public class R {

    private Integer code; // 响应编码: 1成功，0和其它数字为失败
    private String msg; // 提示信息
    private Object data; // 响应数据

    public static R ok(String msg){
        return R.builder().code(1).msg(msg).build();
    }

    public static R error(String msg){
        return R.builder().code(0).msg(msg).build();
    }

    public static R data(Object data){
        return R.builder().code(1).data(data).build();
    }

    public static R page(Long total,Object records){
        Map<String,Object> data = new HashMap<>();
        data.put("records",records);
        data.put("total",total);
        return R.builder().code(1).data(data).build();
    }

}
